<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    a {
        text-decoration: none;
    }

    #app {
        width: 800px;
        height: 500px;
        background-color: rgba(26, 127, 185, 0.3);
        margin: 150px auto;
    }

    .search_form {
        width: 400px;
        margin: auto;
    }

    .search_form img {
        display: block;
        width: 170px;
        margin: auto;
    }

    .form_group {
        width: 250px;
        margin: auto;
        margin-bottom: 20px;
    }

    .form_group input {
        width: 190px;
        height: 25px;
        text-indent: 10px;
        border-radius: 15px;
        outline-style: none;
        border: none;
    }

    .form_group button {
        width: 50px;
        border-radius: 15px;
        outline-style: none;
        border: none;
        height: 25px;
        cursor: pointer;
    }

    .hotkey {
        width: 210px;
        margin-top: 100px;
        margin: auto;
    }

    .hotkey a {
        cursor: pointer;

    }

    .currentCity {
        margin-top: 30px;
        font-size: larger;
    }

    .weather_list {
        width: 800px;
        height: 150px;
        margin-top: 100px;
        display: flex;
        justify-content: space-around;
    }

    .weather_list li {
        text-align: center;
        float: left;
        font-size: 12px;
    }

    .weather_list li b {
        font-size: 13px;
    }

    .weather_list li span {
        display: block;
        margin-top: 20px;
        font-size: 15px;
    }

    .weather_list li p {
        margin-top: 15px;
        font-size: 20px;
    }
</style>

<body>
    <div id="app">
        <div class="search_form">

            <div class="logo"><img src="../../img/1dog.PNG" alt=""></div>

            <div class="form_group">

                <!-- <el-input placeholder="请输入查询的城市" class="input_txt" v-model="city">

                    <el-button slot="append" icon="el-icon-search" @click="searchWeather">
                    </el-button>
                </el-input> -->
                <input type="text" class="input_txt" @keyup.enter="searchWeather" value="搜索" v-model="city">
                <button @click="searchWeather">搜索 </button>
            </div>
            <div class="hotkey">
                <a href="iavaecript:;" @click="changeCity('北京')">北京</a>
                <a href="iavaecript:;" @click="changeCity('上海')">上海</a>
                <a href="iavaecript:;" @click="changeCity('广州')">广州</a>
                <a href="iavaecript:;" @click="changeCity('深圳')">深圳</a>
            </div>
            <div class="currentCity">当前城市：{{city}}</div>
        </div>
        <ul class="weather_list">
            <li v-for="item in weatherList">
                <b>{{item.low}}</b>~<b>{{item.high}}</b>

                <span>{{item.fengxiang}}</span>
                <p>{{item.date}}</p>
            </li>

        </ul>
    </div>


</body>
<script>
    // 地址:http://wthrcdn.etouch.cn/weather_mini?city=武汉
    new Vue({
        el: '#app',
        data: {
            city: '',
            weatherList: []
        },
        methods: {
            async  searchWeather() {
                if (!this.city) return false
                const { data: res } = await axios.get(`http://wthrcdn.etouch.cn/weather_mini?city=${this.city}`)
                console.log(res.data.forecast);
                this.weatherList = res.data.forecast
            },
            changeCity(city) {
                this.city = city
                this.searchWeather()
            }
        },

    })
</script>

</html>